﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Threading;
using System.Globalization;
using BenzInfo.Hockey.Grenadiers.Models;

namespace BenzInfo.Hockey.Grenadiers.Controllers
{
    public class BaseController : Controller
    {
        //
        // GET: /Base/

        protected override void ExecuteCore()
        {
            string lang = (string)Session["lang"] ?? "fr";

            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(lang);
            
            GrenadiersContext db = new GrenadiersContext();

            ViewBag.Partners = db.Partners.Where(
                p => p.ShowInCarousel && !string.IsNullOrEmpty(p.Picture)
            ).OrderBy(p => p.Position).ToList();

            ViewBag.Lang = lang;

            ViewBag.CurrentUser = (BenzInfo.Hockey.Grenadiers.Models.User)Session["User"];
            if (System.Configuration.ConfigurationManager.AppSettings["sessionOpen"] == "")
            {
                System.Configuration.ConfigurationManager.AppSettings["sessionOpen"] = "false";
            }
            else if (System.Configuration.ConfigurationManager.AppSettings["sessionOpen"] == "false")
            {
                System.Configuration.ConfigurationManager.AppSettings["sessionOpen"] = "home";
            }
            else if (System.Configuration.ConfigurationManager.AppSettings["sessionOpen"] == "home")
            {
                System.Configuration.ConfigurationManager.AppSettings["sessionOpen"] = "almost";
            }
            else if (System.Configuration.ConfigurationManager.AppSettings["sessionOpen"] == "almost")
            {
                System.Configuration.ConfigurationManager.AppSettings["sessionOpen"] = "true";
            }

            base.ExecuteCore();
        }
        public class SubmitResult
        {
            public string message;
            public bool success;
        }

    }
}
